package com.csaba.util;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Logger;

//FIXME doc
public class I18N
{
	private final static Logger logger = LoggerHelper.getDefaultLogger();

	public static String getString( final Object namespace, final String key )
	{
		final ResourceBundle bundle = I18NProviderFactory.getProvider().getBundle(namespace);
		if ( bundle == null )
		{
			return key;
		}

		final String className = namespace.getClass().getSimpleName();

		try
		{
			return bundle.getString(className + '.' + key);
		}
		catch ( final MissingResourceException e )
		{
			try
			{
				return bundle.getString(key);
			}
			catch ( final MissingResourceException e2 )
			{
				logger.finest("Cannot find resource for propery " + key + " in package "
						+ namespace.getClass().getName());
				return key;
			}
		}
	}

	public static String getString( final Object namespace, final String key, final Object... arguments )
	{
		final String message = getString(namespace, key);
		return MessageFormat.format(message, arguments);
	}
}
